import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2023-01-11
 * Time:21:31
 */
class MinStack {
    public Stack<Integer> stack1;
    public Stack<Integer> stack2;
    public MinStack() {
        stack1=new Stack<>();
        stack2=new Stack<>();
    }
    public void push(int val) {
        if(stack1.empty()){
            stack1.push(val);
            stack2.push(val);
            return;
        }
        stack1.push(val);
        if(stack1.peek()<=stack2.peek()){
            stack2.push(val);
        }
        return;
    }

    public void pop() {
        if(stack1.peek().equals(stack2.peek())){
            stack1.pop();
            stack2.pop();
        }else{
            stack1.pop();
        }
        return;
    }

    public int top() {
        return stack1.peek();
    }

    public int getMin() {
        return stack2.peek();
    }
}
class MyStack {
    Queue<Integer> quene1;
    Queue<Integer> quene2;
    public MyStack() {
        quene1=new LinkedList<>();
        quene2=new LinkedList<>();
    }

    public void push(int x) {
        if(quene1.isEmpty()&&quene2.isEmpty()){
            quene1.offer(x);
        }else if(quene1.isEmpty()){
            quene2.offer(x);
        }else{
            quene1.offer(x);
        }
    }

    public int pop() {
        if(quene1.isEmpty()&&quene2.isEmpty()){
            return -1;
        }else if(quene1.isEmpty()){
            int size=quene2.size();
            for(int i=0;i<size-1;i++){
                quene1.offer(quene2.poll());
            }
            return quene2.poll();
        }else{
            int size=quene1.size();
            for(int i=0;i<size-1;i++){
                quene2.offer(quene1.poll());
            }
            return quene1.poll();
        }
    }

    public int top() {
        if(quene1.isEmpty()&&quene2.isEmpty()){
            return -1;
        }else if(quene1.isEmpty()){
            int size=quene2.size();
            for(int i=0;i<size-1;i++){
                quene1.offer(quene2.poll());
            }
            int x=quene2.peek();
            quene1.offer(quene2.poll());
            return x;
        }else{
            int size=quene1.size();
            for(int i=0;i<size-1;i++){
                quene2.offer(quene1.poll());
            }
            int x=quene1.peek();
            quene2.offer(quene1.poll());
            return x;
        }
    }

    public boolean empty() {
        if(quene1.isEmpty()&&quene2.isEmpty()){
            return true;
        }
        return false;
    }
}
public class Test {
}
